const app = getApp();
const utils = require('../../utils/utils.js');
Page({
    data: {
        borrow_status: 1, // borrow_status 1 为租借成功 0 为租借失败
        info: {},
    },
    onLoad: function (options) {
        wx.showLoading({
            title: 'loading...',
            mask: true
        })
        let used_id = options.used_id;
        let borrow_status = options.borrow_status;
        this.setData({
            borrow_status: borrow_status
        });
        // 获取使用记录信息
        if (borrow_status == 1) {
            // 租借成功
            wx.setNavigationBarTitle({
                title: '租借成功'
            });
            this.getUsed(used_id);
        } else if (borrow_status == 0) {
            wx.setNavigationBarTitle({
                title: '租借失败'
            });
            this.revokeOrder(used_id);
        }
        app.globalData.create_wxfree = 0;
        wx.hideLoading();
    },
    // ===============  获取使用记录信息 ==========================
    getUsed(used_id) {
        let that = this;
        utils.httpRequest('/getUsed', {
            used_id: used_id
        }, function (res) {
            if (res.code == 1) {
                that.setData({
                    info: res.data
                })
            }
        })
    },
    // ===============  撤销微信分订单 ==========================
    revokeOrder(used_id) {
        utils.httpRequest('/doRevokeOrder', {
            used_id: used_id
        }, function (res) {
            if (res.code == 1) {
                wx.hideLoading();
                wx.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 2000
                });
            }
        })
    },
    // ==================== 跳转到个人用户页面 ==============================
    goToUser() {
        //跳转用户界面
        wx.reLaunch({
            url: '../user/user'
        });
    },
    // ==================  跳转到首页index ===========================
    goToIndex() {
        wx.reLaunch({
            url: '../index/index'
        });
    },

})